﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using HienThi;


namespace GUI
{
    public partial class Form_BanHang_KTV : UserControl
    {
        public Form_BanHang_KTV()
        {
            InitializeComponent();
        }


        private void Form_BanHang_KTV_Load(object sender, EventArgs e)
        {
            BanHangKTVBUS bus = new BanHangKTVBUS();
            List<BanHangKTVHienThi> grdcontrol = new List<BanHangKTVHienThi>();
            grdcontrol = bus.LayLayBangBanHangKTV();
            grdcontrolBanHangKTV.DataSource = grdcontrol;

            List<ThanhVien> cbb = new List<ThanhVien>();
            cbb = bus.LayBangThanhVien();
            cbbThanhVien.Properties.DataSource = cbb;
            cbbThanhVien.ItemIndex = 0;

            txtNgayMuaHang.EditValue = DateTime.Now.ToShortDateString();
            txtThanhTien.Properties.ReadOnly = true;
        }

        private void grdviewBanHangKTV_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column.FieldName == "SoLuong")
            {
                int dong = e.RowHandle;
                float dongia = float.Parse(grdviewBanHangKTV.GetRowCellValue(dong, "DonGia").ToString());
                int soluong = int.Parse(grdviewBanHangKTV.GetRowCellValue(dong, "SoLuong").ToString());
                float thanhtien = soluong * dongia;
                grdviewBanHangKTV.SetRowCellValue(dong, "ThanhTien", thanhtien.ToString());
                double tientt = double.Parse(txtThanhTien.EditValue.ToString()) + thanhtien;
                tientt += (tientt * 0.1);
                txtThanhTien.EditValue = tientt.ToString();

            }
        }

    }
}
